/** 
 * Copyright (C), 2010-2012, TIETIAO Software Co.,Ltd. ALL RIGHTS RESERVED. 
 * File name:CommidityFavoriteServiceImpl.java
 * Version:1.0
 * Date:2011-12-14
 * Description: 
 * author:zhijian.zhang
 */
package com.tietiao.service.tietiao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.tietiao.dao.UserCommidityFavoriteMapper;
import com.tietiao.dao.model.UserCommidityFavorite;
import com.tietiao.dao.model.UserCommidityFavoriteCriteria;

@Service
public class CommidityFavoriteServiceImpl implements CommidityFavoriteService {

	@Resource
	private UserCommidityFavoriteMapper userCommidityFavoriteMapper;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.tietiao.service.tietiao.CommidityFavoriteService#
	 * getUserCommidityFavorites(int, java.lang.String)
	 */
	@Override
	public List<UserCommidityFavorite> getUserCommidityFavorites(int userId,
			String orderByClause) {

		UserCommidityFavoriteCriteria userCommidityFavoriteCriteria = new UserCommidityFavoriteCriteria();
		userCommidityFavoriteCriteria.setOrderByClause(orderByClause);
		UserCommidityFavoriteCriteria.Criteria criteria = userCommidityFavoriteCriteria
				.createCriteria();
		criteria.andUserIdEqualTo(userId);
		return userCommidityFavoriteMapper
				.selectByExample(userCommidityFavoriteCriteria);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.tietiao.service.tietiao.CommidityFavoriteService#addUserCommidityFavorite
	 * (com.tietiao.dao.model.UserCommidityFavorite)
	 */
	@Override
	public int addUserCommidityFavorite(
			UserCommidityFavorite userCommidityFavorite) {
		userCommidityFavoriteMapper.insert(userCommidityFavorite);
		return userCommidityFavorite.getFavoriteId();
	}

	@Override
	public List<UserCommidityFavorite> searchFavsByFavName(String favName,
			Integer loginUserId, Integer start, Integer limit,
			String orderByClause) {

		return userCommidityFavoriteMapper.searchFavsByFavName(favName,
				loginUserId, start, limit, orderByClause);

	}
}
